package com.gxa.weixing.portal.service.impl;

import com.gxa.weixing.core.pojo.Address;
import com.gxa.weixing.core.service.impl.BaseServiceImpl;
import com.gxa.weixing.portal.mapper.AddressMapper;
import com.gxa.weixing.portal.service.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Author HHT
 * 2022/1/11
 */
@Service
@Transactional
public class AddressServiceImpl extends BaseServiceImpl<Address> implements AddressService {

    @Autowired
    AddressMapper addressMapper;

    @Override
    public void adds(Address address) {
        Boolean ifDefault = address.getIfDefault();
        if (ifDefault) {
            addressMapper.updates(address.getUserId());
        }
        addressMapper.insert(address);
    }

    @Override
    public void updates(Address address) {
        //思路。可以先把全部改为0，再把要修改的改为默认
        addressMapper.updates(address.getUserId());
        //再把需要的改成默认地址
        addressMapper.updateByPrimaryKey(address);
    }
}
